﻿using MahApps.Metro.IconPacks;
using System;
using System.Windows;

namespace Com.Lancetinc.Evs.Controls
{
    /// <summary>
    /// 圆形按钮
    /// </summary>
    public partial class CircleButton
    {
        #region Icon

        public static readonly DependencyProperty IconProperty
            = DependencyProperty.Register(nameof(Icon),
                typeof(string),
                typeof(CircleButton),
                new PropertyMetadata(null, OnIconChanged));

        private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as CircleButton).UpdateIcon();
        }

        public string Icon
        {
            get => (string)this.GetValue(IconProperty);
            set => this.SetValue(IconProperty, value);
        }

        #endregion

        public CircleButton()
        {
            InitializeComponent();
        }

        private void UpdateIcon()
        {
            if (Enum.TryParse<PackIconLevsKind>(Icon, out var kind))
            {
                this.Content = new PackIconLevs
                {
                    Kind = kind,
                    Width = 20,
                    Height = 20
                };
            }
        }
    }
}